﻿@model FineAdmin.Model.BlogCommentModel
@{ ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_LayoutForm.cshtml"; }
<link href="~/Scripts/umeditor/themes/default/css/umeditor.min.css" rel="stylesheet" />
<script src="~/Scripts/umeditor/third-party/jquery.min.js"></script>
<script src="~/Scripts/umeditor/umeditor.config.js"></script>
<script src="~/Scripts/umeditor/umeditor.min.js"></script>
<script src="~/Scripts/umeditor/lang/zh-cn/zh-cn.js"></script>
<form class="layui-form layui-form-pane ok-form" lay-filter="formTest">
    @*一些不需要更新的隐藏字段*@
    @Html.HiddenFor(x => x.Id)
    @Html.HiddenFor(x => x.CreateTime)
    @Html.HiddenFor(x => x.CreateUserId)
    @Html.HiddenFor(x => x.PostsId)
    <div class="layui-tab layui-tab-card">
        <ul class="layui-tab-title">
            <li class="layui-this">文章概要</li>
            <li>文章内容</li>

        </ul>
        <div class="layui-tab-content" style="">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label">UserId</label>
                    <div class="layui-input-block">
                        <input type="text" name="UserId" placeholder="UserId" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">IP</label>
                    <div class="layui-input-block">
                        <input type="text" name="IP" placeholder="IP" autocomplete="off" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">City</label>
                    <div class="layui-input-block">
                        <input type="text" id="City" name="City" placeholder="城市" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-block">
                        <input type="text" id="Phone" name="Phone" placeholder="手机" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">E-Mail</label>
                    <div class="layui-input-block">
                        <input type="text" id="EMail" name="EMail" placeholder="电子邮件" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <select name="Type" lay-filter="aihao">
                            <option value="">全部</option>
                            <option value="1">文章留言</option>
                            <option value="2">网站留言</option>
                            <option value="3">问题建议</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        @*<input type="text" name="State" placeholder="1 正常 2 草稿 3 隐藏 " autocomplete="off" class="layui-input">*@
                        <select name="State">
                            <option value="2">审核</option>
                            <option value="1">正常</option>
                            <option value="3">废弃</option>
                        </select>
                    </div>
                </div>
                @*<div class="layui-form-item">
                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="Stime" id="Stime" placeholder="开始时间" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">有效时间至</label>
                        <div class="layui-input-block">
                            <input type="text" name="Indate" id="Indate" placeholder="有效时间至" autocomplete="off" class="layui-input">
                        </div>
                    </div>*@

                <div class="layui-form-item">
                    <label class="layui-form-label">点击</label>
                    <div class="layui-input-block">
                        <input type="text" name="Clicks" placeholder="点击" autocomplete="off" class="layui-input" maxlength="10">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">赞</label>
                    <div class="layui-input-block">
                        <input type="text" name="Likes" placeholder="赞" autocomplete="off" class="layui-input" maxlength="10">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">踩</label>
                    <div class="layui-input-block">
                        <input type="text" name="Trample" placeholder="踩" autocomplete="off" class="layui-input" maxlength="10">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序码</label>
                    <div class="layui-input-block">
                        <input type="text" name="SortCode" placeholder="排序码" autocomplete="off" class="layui-input" lay-verify="number" maxlength="5">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item col-md-12">
                <!--<div class="layui-form-item">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">-->
                @*<textarea id="demo" style="display: none;" name="PostContent">@Html.Raw(Model.PostContent)</textarea>*@
                <!--</div>
                </div>-->


                <script type="text/plain" id="myEditor" name="Contents" style="width:1000px;height:580px">

                </script>
            </div>
        </div>
    </div>


</form>
<script>
    window.UMEDITOR_HOME_URL = "${base}/scripts/umeditor";/** "相对于网站根目录的相对路径"**/
    var um = UM.getEditor('myEditor', {
        imagePath: '',/**图片网络显示路径**/


    });

    um.setContent('@Html.Raw(Model.Contents)');
    layui.use(["form", "element", "layedit", "treeSelect", "okLayer", "okUtils", 'laydate'], function () {
        let treeSelect = layui.treeSelect;
        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        var layedit = layui.layedit;
        var element = layui.element;
        var laydate = layui.laydate;
        //laydate.render({
        //    elem: '#Stime' //指定元素
        //    , type: 'datetime'
        //});
        //laydate.render({
        //    elem: '#Indate' //指定元素
        //    , type: 'datetime'
        //});
        layedit.set({
            uploadImage: {
                url: '@Url.Action("ExportFile", "PostSet")' //接口url
                , type: 'post' //默认post
            }
        });

        @*treeSelect.render({
            elem: "#Post_Type",
            data: "/Blog/BlogPostsCategorieSet/GetTreeSelect",
            type: "GET"
            @if (Model.CId!=0)
            {
                <text>,success: function (d) {
                treeSelect.checkNode('tree', "@Model.CId");
                treeSelect.refresh('tree');
                }</text>
            }
        });*@

        //给表单赋值
        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "UserID": "@Model.UserID",
            "IP": "@Model.IP",
            "City": "@Model.City",
            "PostsId": "@Model.PostsId",
            "Type": "@Model.Type",
            "Pid": "@Model.Pid",
            "SortCode": "@Model.SortCode",
            "Clicks": "@Model.Clicks",
            "Likes": "@Model.Likes",
            "Trample": "@Model.Trample",
            "EMail": "@Model.EMail",
            "Phone": "@Model.Phone",

        });

        var index = layedit.build('demo',{
            height: 600 //设置编辑器高度
        }); //建立编辑器

        form.on("submit(add)", function (data) {

            var arr_box = [];
            $('input[name="Label"][type=checkbox]:checked').each(function () {
                arr_box.push($(this).val());
            });
            data.field.Label = arr_box.join(",");

            //var edit = layedit.getContent(index);
            //data.field.PostContent = UM.getEditor('myEditor').getContent();
            okUtils.ajax("/Blog/BlogCommentSet/Edit", "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.message, function () {
                    parent.location.reload(); // 父页面刷新
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引 再执行关闭
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>

